/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SessionBeans;

import Entidades.Product;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Pedro
 */
@Stateless
public class ProductFacade extends AbstractFacade<Product> {
    @PersistenceContext(unitName = "WebApplicationPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public ProductFacade() {
        super(Product.class);
    }
    
    public List<Product> findList(String des){
        Query q =null;
        
            q = (Query) em.createQuery("select p FROM Product p where p.description LIKE :description");
            q.setParameter("description", "%" + des + "%");
            return (List<Product>) q.getResultList();
               
                
    }
    
    public Product findPes(Integer id){
        Query q = null;
        q = (Query) em.createQuery("select p FROM Product p where p.ID = :ID");
        q.setParameter("ID", id);
        return (Product) q.getSingleResult();
        
    }   
    
}
